package com.tender.service.impl;


import lombok.extern.slf4j.Slf4j;
import com.tender.mapper.OrderMapper;
import org.springframework.stereotype.Service;
import com.tender.domain.*;
import com.tender.service.*;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;

    @Override
    public int insertSelective(Order param) {

        return orderMapper.insertSelective(param);
    }

    @Override
    public int updateByCondition(OrderCondition param) {

        OrderExample example = new OrderExample();
        OrderExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(param.getId());
        criteria.andStatusEqualTo(0);

        return orderMapper.updateByExampleSelective(param, example);
    }

    @Override
    public Order selectOne(OrderCondition param) {
        OrderExample example = new OrderExample();
        OrderExample.Criteria criteria = example.createCriteria();

        criteria.andIdEqualTo(param.getId());
        List<Order> orderList = orderMapper.selectByExample(example);

        return CollectionUtils.isEmpty(orderList) ? null : orderList.get(0);
    }
}
